﻿using JunionRobotTaskManager.Models;
using Polly;
using System.Runtime.CompilerServices;

namespace JunionRobotTaskManager.Extensions
{
    public static class RobotExtension
    {

        public static  bool ExcutePath(this Robot robot,string route,string jobid,ILogger logger=null)
        {
            return  Policy.HandleResult<bool>(x=>x==false)
            .WaitAndRetry<bool>(6,retryAttempt => TimeSpan.FromSeconds(1.5)).Execute(() =>
            {
                var result=robot.RoutesWithConfirm(route, jobid);
                if (logger != null && !result)
                {
                    logger.LogDebug($"The robot({robot.IP}) status is:{robot.Status},go to next target:{robot.CurrentJob.CurrentTarget} failed..............");
                }
                return result;
            });
        }
    }
}
